<%@page import="java.util.List"%>
<%@page import="java.sql.*"%>
<%@page import="org.barman.dao.UserDAO"%>
<%@page import="org.barman.pojo.User"%>
<%@page import="org.barman.dao.ItemDAO"%>
<%@page import="org.barman.pojo.Item"%>

<%@include file="/layout/header.jspf"%>

<%
	UserDAO userDAO = new UserDAO();
	List<User> userList = userDAO.getAll();
	
	ItemDAO itemDAO = new ItemDAO();
	List<Item> itemList = itemDAO.getAll();	
%>

<center>
	<br>
	<h1>Admin Main Page</h1>
	<div id="admin_main">
		<a href="manage_user.jsp?action=add">Add user</a> <br /> <br>
		<table BORDER="1" CELLPADDING="3" CELLSPACING="1">
			<TR>
				<TH>Username</TH>
				<TH>Email</TH>
				<TH>First Name</TH>
				<TH>Last Name</TH>
				<TH>Role</TH>
				<TH>Created</TH>
				<TH>EDIT</TH>
			</TR>
			<%
				for (User us : userList) {
			%>
			<tr>
				<td>
					<%
						out.print(us.getUsername());
					%>
				</td>
				<td>
					<%
						out.print(us.getEmail());
					%>
				</td>
				<td>
					<%
						out.print(us.getFirstName());
					%>
				</td>
				<td>
					<%
						out.print(us.getLastName());
					%>
				</td>
				<td>
					<%
						out.print(us.getRole().toString());
					%>
				</td>
				<td>
					<%
						out.print(us.getCreated());
					%>
				</td>
				<td>
					<%
						out.print("<a href=\"manage_user.jsp?action=edit&id="
									+ us.getId().toString() + "\">" + "Edit</a>");
					%>
				</td>
			<tr>
				<%
					}
				%>
			
		</table>
		<br /> <br> <a href="manage_item.jsp?action=add">Add item</a> <br />
		<table BORDER="1" CELLPADDING="3" CELLSPACING="1">
			<TR>
				<TH>Name</TH>
				<TH>Price</TH>
				<TH>Created</TH>
				<TH>EDIT</TH>
			</TR>
			<%
			for(Item it : itemList){
			%>
			<tr>
				<td>
					<%
						out.print(it.getName());
					%>
				</td>
				<td>
					<%
						out.print(it.getPrice());
					%>
				</td>
				<td>
					<%
						out.print(it.getCreated());
					%>
				</td>
				<td>
					<%
						out.print("<a href=\"manage_item.jsp?action=edit&id="
									+ it.getId().toString() + "\">" + "Edit</a>");
					%>
				</td>
			<tr>
				<%
					}
				%>
			
		</table>
		<br>
	</div>
</center>
<%@include file="/layout/footer.jspf"%>
